package com.abc.springboot.controller;

import com.abc.springboot.util.AliOssUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

@RestController
public class FileUploadController {

    @RequestMapping("/upload")
    public String upload(MultipartFile file) throws Exception {
        String originalFilename=file.getOriginalFilename();
//        file.transferTo(new File("D:\\IOTest\\"+originalFilename));
        String filename= UUID.randomUUID().toString()+originalFilename.substring(originalFilename.lastIndexOf("."));
        String url= AliOssUtil.uploadFile(filename,file.getInputStream());
//        System.out.println(url);
        return url;
    }

}
